package spbun.fileclean.ui;

import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;

import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;

public class MainFrame extends JFrame implements ActionListener {

	/**
	 * serialVersionUID
	 */
	private static final long serialVersionUID = -7871840000401970942L;

	/** 重建索引 */
	private JButton btnFindBigFile = null;

	public MainFrame() {
		super();
		initGui();
	}

	private void initGui() {

		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		this.setTitle("文件空间扫描工具");
		this.setLayout(new BorderLayout(15, 15));

		initCenterPanel();
		initSouthPanel();

		this.setSize(800, 600);
		this.setLocationRelativeTo(null);

	}

	private void initCenterPanel() {

		JPanel panel = new JPanel();
		panel.setBorder(BorderFactory.createTitledBorder("选择要比较的文件夹或者磁盘"));
		panel.setLayout(new BorderLayout());

		// 右侧的按钮
		JPanel rightPanel = new JPanel();
		rightPanel.setLayout(new BoxLayout(rightPanel, BoxLayout.Y_AXIS));
		rightPanel.add(new JButton("[Add]增加一个目录"));
		rightPanel.add(new JButton("[Del]删除选中目录"));
		panel.add(rightPanel, BorderLayout.EAST);

		JList<File> lstForder = new JList<>();
		JScrollPane jsp = new JScrollPane(lstForder);
		panel.add(jsp, BorderLayout.CENTER);

		this.add(panel, BorderLayout.CENTER);
	}

	private void initSouthPanel() {
		JPanel panel = new JPanel(new FlowLayout(FlowLayout.CENTER));
		panel.add(new JButton("开始扫描"));
		this.add(panel, BorderLayout.SOUTH);
	}

	@Override
	public void actionPerformed(ActionEvent e) {

		if (e.getSource().equals(btnFindBigFile)) {
			rebuildCacheClick();
		}
	}

	private void rebuildCacheClick() {
	}
}
